using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using LTreesLibrary.Trees;
using LTreesLibrary.Trees.Wind;

namespace Advanced_Terrain
{



    public class Game1 : Microsoft.Xna.Framework.Game
    {
        AudioEngine engine;
        public static SoundBank soundBank;
        WaveBank waveBank;
        public static Sky MySky;
        CullingClass myCulling;
        SkyGameComponent SkyComp;
        public const int GameStateAiming = 0;
        public const int GameStateFlying = 1;
        public const int GameStateLanded = 2;
        public const int GameStateWater = 3;
        public const int GameStateInBasket = 4;
        public const int GameStateShakingChains = 5;
        public const int GameStateZoomingToBasket = 6;
        public const int GameStateDisplayingScores = 7;
        public const int GameStateNoCameraMove = 8;
        public const int GameStateMenuPlayers = 9;
        public const int GameStateSwitchMenus = 10;
        public const int GameStateOB = 11;
        public const int GameStatePreAiming = -1;
        public const int GameStateMenu = -2;
        public const int GameStateLoadHole = -3;
        public const int GameStateChooseDisc = -4;
        public const int GameStateVertPower = -5;
        public const int GameStateHorPower = -6;
        public const int GameStatePlayerProperties = -7;
        public const int GameStateWiiMoteSwinging = -8;
        public const int GameStateWiiMoteCalc = -9;
        public static int GameState = -2;
        public static KeyboardHandling MyKeyboard;
        
        public static int CourseHoles;
        public static String EndofCourseName;
        public static int PowerCounter = 0;
        public static bool PowerSwitch = false;
        public static int PowerDelay = 0;
        public static bool VerticleView = false;
        Texture2D VerticlePower;
        Texture2D VerticleIncrement;
        Texture2D HorizontalPower;
        Texture2D HorizontalIncrement;
        //SimpleTree Tree;
        
        //Rendertarget testing
        RenderTarget2D renderTarget;
        Texture2D Arrow;
        public static Menu mainMenu;
        public static ScrollingMenu DiscSelection;
        Boolean FirstTime = true;
        public static int NumberOfPlayers;
        public static CustomDiscList DiscOptions = new CustomDiscList();
        //CustomDiscList Test;

        public static GraphicsDeviceManager graphics;
        GraphicsDevice device;
        TextObject Power = new TextObject();
        TextObject AngleOfAttack = new TextObject();
        TextObject DiscStatus = new TextObject();
        TextObject PlayerStatus = new TextObject();
        TextObject BasketInformation = new TextObject();

        public static Player[] Players = new Player[10];
        public const int TerrainAdjuster = 10; //Keeps camera from leaving the edges
        public static int Delay = 0;
        
        public static Matrix viewMatrix;
        //Matrix projectionMatrix;
        public static Matrix reflectionViewMatrix;
        public static float TerrainHeight;
        public static Disc newDisc;
        WindArrow newArrow;
        DiscHUD newDiscHud;
        public static Basket newBasket;
        public static Terrain newTerrain;



        
        
        public static Matrix cameraRotation;
        Vector3 LightDirection = new Vector3(-.5f, -1f, -1f);
        
        
        
        
        
        public static string CoursePath = "Courses\\OriginalCourse\\";
        public static int HoleNum = 1;
        public static int CurrentPlayer = 0;

        Texture2D ScoreBoard;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            device = GraphicsDevice;
            graphics.SynchronizeWithVerticalRetrace = false;
            this.TargetElapsedTime = TimeSpan.FromMilliseconds(10);
            //this.IsFixedTimeStep = false;
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.IsFullScreen = false;
            //graphics.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
            graphics.ApplyChanges();
            
            VerticlePower = Content.Load<Texture2D>("PowerBars/VerticalPower");
            VerticleIncrement = Content.Load<Texture2D>("PowerBars/VerticalIncreaser");
            HorizontalPower = Content.Load<Texture2D>("PowerBars/HorizontalPower");
            HorizontalIncrement = Content.Load<Texture2D>("PowerBars/HorizontalIncrement");
            
            Advanced_Terrain.CameraProperties.cameraPosition = new Vector3(130, 30, -50);
            Window.Title = "DG_Game";
            Power.Position.X = 650f;
            Power.Position.Y = 400f;
            Power.TextLabel = "Current Disc:  ";
            Power.TextValue = 0;
            Power.Visible = true;

            DiscStatus.Center = true;
            DiscStatus.TextColor = Color.BlanchedAlmond;
            DiscStatus.TextLabel = "Middle";
            DiscStatus.TextValue = 0;
            DiscStatus.Position.X = graphics.GraphicsDevice.Viewport.Width / 2;
            DiscStatus.Position.Y = graphics.GraphicsDevice.Viewport.Height / 2;
            DiscStatus.Visible = false;
            AngleOfAttack.Position.X = 10f;
            AngleOfAttack.Position.Y = 30f;
            AngleOfAttack.TextLabel = "Release Angle: ";
            AngleOfAttack.TextValue = 0;
            AngleOfAttack.Visible = true;
            PlayerStatus.Position.X = graphics.GraphicsDevice.Viewport.Width - 175f - 500f;
            PlayerStatus.Position.Y = 10f;
            PlayerStatus.Visible = true;
            PlayerStatus.TextLabel = "None";
            BasketInformation.Position.X = 10f;
            BasketInformation.Position.Y = 50f;
            BasketInformation.Visible = true;
            BasketInformation.TextLabel = "None";
            Power.spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            AngleOfAttack.spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            DiscStatus.spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            PlayerStatus.spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            BasketInformation.spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            this.Components.Add(MyKeyboard = new KeyboardHandling(this, device.Viewport.Width, device.Viewport.Height));
            this.Components.Add(myCulling = new CullingClass(this));
            
            
            this.Components.Add(newTerrain = new Terrain(this, Content, device));
            this.Components.Add(SkyComp = new SkyGameComponent(this));
            this.Components.Add(newBasket = new Basket(this, Content));
            this.Components.Add(newDisc = new Disc(this, Content));
            this.Components.Add(newArrow = new WindArrow(this, Content));
            this.Components.Add(newDiscHud = new DiscHUD(this, Content));


            
            //Players[0] = new Player();
            //Players[0].Name = "Player 1";
            //Players[0].IsActive = true;
            //Players[1] = new Player();
            //Players[1].Name = "Player 2";
            //Players[1].IsActive = true;


            engine = new AudioEngine("Content\\Audio\\DiscGolf.xgs");
            soundBank = new SoundBank(engine, "Content\\Audio\\Sound Bank.xsb");
            waveBank = new WaveBank(engine, "Content\\Audio\\Wave Bank.xwb");

            base.Initialize();


        }

        protected override void LoadContent()
        {



            MySky = Content.Load<Sky>("sky");
            MyKeyboard.UpdateViewMatrix();
            Advanced_Terrain.CameraProperties.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.3f, 1000.0f);
            



            
            ScoreBoard = Content.Load<Texture2D>("DiscGolfScoreCard");
            Power.font = Content.Load<SpriteFont>("GameFont");

            AngleOfAttack.font = Power.font;
            DiscStatus.font = Power.font;
            PlayerStatus.font = Power.font;
            BasketInformation.font = Power.font;
            DiscSelection = new ScrollingMenu();
            DiscSelection.Background = Content.Load<Texture2D>("MenuBackGrounds/DiskSelection");
            DiscSelection.SetSpriteBatch(device);
            DiscSelection.SetFont(Power.font);

            mainMenu = new Menu();
            mainMenu.MenuItems.Add("Start");
            mainMenu.MenuItems.Add("Connect Motion++");
            mainMenu.WiiMoteCalibration.Add("Hold B and the WiiMote Flat for 3-4 secs");
            mainMenu.WiiMoteCalibration.Add("Please wait....");
            mainMenu.WiiMoteSearching.Add("Hold 1+2 and please wait.....");


            //mainMenu.MenuItems.Add("Select Players");
            //mainMenu.MenuItems.Add("Select Course");
            mainMenu.MenuItems.Add("Exit");

            mainMenu.PlayerItems.Add("1");
            mainMenu.PlayerItems.Add("2");
            mainMenu.PlayerItems.Add("3");
            mainMenu.PlayerItems.Add("4");
            mainMenu.PlayerItems.Add("Back");
            mainMenu.Background = Content.Load<Texture2D>("MenuBackGrounds/MenuScreen");
            mainMenu.SetSpriteBatch(device);
            mainMenu.SetFont(Power.font);
            mainMenu.CourseItems.Add("Big Sioux, SD, 18");
            mainMenu.CourseItems.Add("Michigan Tech University, MI, 9");
            mainMenu.CourseItems.Add("Sunnybrook, MN, 9");
            mainMenu.CourseItems.Add("Watertown - Slumberland, SD , 18");
            mainMenu.CourseItems.Add("Custom Course, c:\\DGCourse , 18");
            mainMenu.ThrowingMethods.Add("Right Hand Backhand");
            mainMenu.ThrowingMethods.Add("Right Hand Forehand");
            mainMenu.ThrowingMethods.Add("Left Hand Backhand");
            mainMenu.ThrowingMethods.Add("Left Hand Forehand");

            mainMenu.SetSpriteBatch(device);
            mainMenu.SetFont(Power.font);
            
            DiscOptions = new CustomDiscList();
            DiscOptions = DiscOptions.LoadMe(@"Content/DiscTextures/CustomDisc.xml");
            SetDiscSelectionMenu();


        }
        private void SetDiscSelectionMenu()
        {
            DiscSelection.LocalDiscOptions = DiscOptions;
            for (int Q = 0; Q < DiscOptions.DiscInfo.Count; Q++)
            {
                if (DiscOptions.DiscInfo[Q].IsActive)
                {
                    DiscSelection.MenuItems.Add(DiscOptions.DiscInfo[Q].Name);
                    DiscSelection.PlayerItems.Add(Q);
                }
            }
            DiscSelection.NextItem();
            DiscSelection.PrevItem();
        }



        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            switch (GameState)
            {

                case GameStatePreAiming:
                    {
                        newTerrain.Visible = false; SkyComp.Visible = false;
                        //float test = newDisc.Position.X + newDisc.Position.Z;

                        //AngleOfAttack.TextValue = 0;
                        if (Delay >= 1)
                        {
                            Delay--;
                        }
                        else
                        {
                            int NextPlayer = 0;
                            Boolean EveryoneIn = true;
                            if (FirstTime)
                            {
                                EveryoneIn = false;
                                FirstTime = false;
                                newBasket.IsVisible = true;
                                CurrentPlayer = NextPlayer;
                                PlayerStatus.TextLabel = Players[CurrentPlayer].Name + " " + "shooting: " + Convert.ToString(Players[CurrentPlayer].CurrentStrokes);
                                if (DiscSelection.DiscIndex == null)
                                    DiscSelection.DiscIndex = 0;
                                Power.TextLabel = DiscOptions.DiscInfo[DiscSelection.DiscIndex].Manufacturer + " " + DiscOptions.DiscInfo[DiscSelection.DiscIndex].Texture;
                                AngleOfAttack.TextValue = 0;
                                newDisc.Position = Players[CurrentPlayer].CurrentDiscPosition;
                                cameraRotation = Matrix.CreateFromQuaternion(newDisc.Rotation);
                                MyKeyboard.SetLeftRightRot();
                                GameState = GameStateAiming;
                                BasketInformation.TextLabel = "Distance to basket: " + Convert.ToString(Math.Round(Vector3.Distance(newDisc.Position, newDisc.BasketPosition) * 5, 0) + "ft");
                                DiscStatus.Visible = false;
                                GC.Collect();
                            }
                            else
                            {
                                Players[CurrentPlayer].CurrentStrokes++;
                                Players[CurrentPlayer].DistanceToBasket = Vector3.Distance(newDisc.Position, newBasket.Position);
                                Players[CurrentPlayer].CurrentDiscPosition = newDisc.Position;
                                newDisc.Position.Y += 3.5f;
                                float MinDistance = 0;


                                for (int Q = 0; Q < NumberOfPlayers; Q++)
                                {
                                    if (Players[Q].InHole == false)
                                    {
                                        EveryoneIn = false;
                                        if (Players[Q].DistanceToBasket > MinDistance)
                                        {
                                            NextPlayer = Q;
                                            MinDistance = Players[Q].DistanceToBasket;
                                        }
                                    }
                                }
                                if (!EveryoneIn)
                                {
                                    newBasket.IsVisible = true;
                                    CurrentPlayer = NextPlayer;
                                    PlayerStatus.TextLabel = Players[CurrentPlayer].Name + " " + "shooting: " + Convert.ToString(Players[CurrentPlayer].CurrentStrokes);
                                    Power.TextValue = 100;
                                    AngleOfAttack.TextValue = 0;
                                    newDisc.Position = Players[CurrentPlayer].CurrentDiscPosition;
                                    cameraRotation = Matrix.CreateFromQuaternion(newDisc.Rotation);
                                    MyKeyboard.SetLeftRightRot();
                                    GameState = GameStateAiming;
                                    BasketInformation.TextLabel = "Distance to basket: " + Convert.ToString(Math.Round(Vector3.Distance(newDisc.Position, newDisc.BasketPosition) * 5, 0) + "ft   ");
                                    DiscStatus.Visible = false;
                                    GC.Collect();
                                }
                                else
                                {
                                    for (int Q = 0; Q < NumberOfPlayers; Q++)
                                    {
                                        Players[Q].HoleScore[HoleNum - 1] = Players[Q].CurrentStrokes - 1;
                                        Players[Q].InHole = false;
                                    }
                                    GameState = GameStateDisplayingScores;
                                }


                            }
                        }
                        break;
                    }
                case GameStateAiming:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        BasketInformation.TextLabel = "Distance to basket: " + Convert.ToString(Math.Round(Vector3.Distance(newDisc.Position, newDisc.BasketPosition) * 5, 0) + "ft   ");
                        Power.TextValue = 0;
                        Power.TextColor = Color.White;
                        Power.TextLabel = DiscOptions.DiscInfo[DiscSelection.DiscIndex].Manufacturer + " " + DiscOptions.DiscInfo[DiscSelection.DiscIndex].Texture;
                        Power.Position.X = 675f - (Power.font.MeasureString(Power.TextLabel).X / 2);
                        //BasketInformation.TextLabel = "X: " + newDisc.Position.X.ToString() + " Y: " + newDisc.Position.Y.ToString() + " Z: " + newDisc.Position.Z.ToString();
                        if (DiscSelection.DiscIndex == null)
                            DiscSelection.DiscIndex = 0;
                        newDiscHud.visible = true;
                        newDiscHud.DiscInfo = DiscOptions.DiscInfo[DiscSelection.DiscIndex];
                        CameraProperties.CameraFloating = CameraProperties.CameraFloatingOnDisk;
                        
                        break;
                    }
                case GameStateFlying:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        //BasketInformation.TextLabel = "Gamestateflying" ;
                        newDiscHud.visible = false;
                        newArrow.Visible = false;
                        
                        //PlayerStatus.Position -= new Vector2(100, 0);
                        //PlayerStatus.TextLabel = "PowerChanger: " + WiiMotePowers.X.ToString() + " Angle Changer : " + MyWiimote.Angle.Z.ToString();
                        break;
                    }
                case GameStateLanded:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        CameraProperties.CameraFloating = CameraProperties.CameraFloatingNo;
                        break;
                    }
                case GameStateWater:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        newDisc.Position = newBasket.DropZone;
                        newDisc.Position.Y = newTerrain.GetTerrainHeight(newDisc.Position.X, newDisc.Position.Z * -1) + .9f;
                        DiscStatus.TextLabel = "You hit the water.  Placing disc in drop zone.";
                        DiscStatus.Visible = true;
                        GameState = GameStatePreAiming;
                        Players[CurrentPlayer].CurrentStrokes++;
                        Delay = 60;
                        break;
                    }
                case GameStateOB:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        newDisc.Position = newBasket.DropZone;
                        newDisc.Position.Y = newTerrain.GetTerrainHeight(newDisc.Position.X, newDisc.Position.Z * -1) + .9f;
                        DiscStatus.TextLabel = "You went out of bounds. Placing disc in drop zone.";
                        DiscStatus.Visible = true;
                        GameState = GameStatePreAiming;
                        Players[CurrentPlayer].CurrentStrokes++;
                        Delay = 60;
                        break;
                    }
                case GameStateMenu:
                    {
                        newTerrain.Visible = false; SkyComp.Visible = false;
                        //device.Clear(Color.Blue);
                        mainMenu.Update();

                        //newBasket.IsVisible = false;
                        break;
                    }

                case GameStateInBasket:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        HoleNum++;
                        GameState = GameStateLoadHole;
                        break;
                    }
                case GameStateLoadHole:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        newDisc.BasketPosition = newBasket.Position;
                        newDisc.Position = newBasket.DiscInitialPosition;
                        cameraRotation = Matrix.CreateFromQuaternion(newDisc.Rotation);
                        MyKeyboard.SetLeftRightRot();
                        newDisc.Position.Y = newTerrain.GetTerrainHeight(newDisc.Position.X, newDisc.Position.Z * -1) + .9f;
                        for (int X = 0; X < NumberOfPlayers; X++)
                        {
                            if (Players[X].IsActive)
                            {
                                Players[X].DistanceToBasket = Vector3.Distance(newDisc.Position, newBasket.Position);
                                Players[X].CurrentDiscPosition = newDisc.Position;
                                Players[X].CurrentStrokes = 1;
                            }
                        }
                        CurrentPlayer = 0;
                        FirstTime = true;
                        GameState = GameStatePreAiming;

                        break;
                    }
                case GameStateShakingChains:
                    {
                        newTerrain.Visible = true; SkyComp.Visible = true;
                        if (Delay > 1)
                        {
                            Delay--;
                        }
                        else
                        {
                            GameState = GameStatePreAiming;
                        }
                        break;
                    }
                case GameStateZoomingToBasket:
                    newTerrain.Visible = true; SkyComp.Visible = true;
                    break;
                case GameStateSwitchMenus:
                    newTerrain.Visible = false; SkyComp.Visible = false;
                    if (Delay > 1)
                        Delay--;
                    else
                        GameState = GameStateMenu;
                    break;
            }

            if (Delay < 1)
            {
                float timeDifference;
                timeDifference = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
                MyKeyboard.ProcessInput(timeDifference, gameTime);
                if (GameState != GameStateMenu)
                {
                    if (GameState != GameStateLoadHole)
                    {
                        if (GameState != GameStateMenuPlayers)
                        {
                            if (GameState != GameStateSwitchMenus)
                            {
                                newTerrain.Visible = true; SkyComp.Visible = true;
                                newBasket.UpdatePosition();
                                newDisc.UpdatePosition(gameTime);
                                newDisc.BasketPosition = newBasket.Position;
                            }
                        }
                    }
                }
            }

            //Vector3 TransformedDisc;
            //TransformedDisc = newDisc.Position;
            //DiscStatus.TextLabel = "Distance to nearest tree = " + Convert.ToString(newDisc.DistanceToBasket) + " Y: " + Convert.ToString(newDisc.TranslatedPosition.Y-newDisc.CurrentTerrainHeight);
            // DiscStatus.TextLabel = "Y: " + Convert.ToString(newDisc.Position.Y) + "  Z: " + Convert.ToString(newDisc.Direction.Z) + "  Y: " + Convert.ToString(newDisc.Direction.Y);
            //DiscStatus.TextValue = TransformedDisc.Z;
            //DiscStatus.Visible = true;
            //BasketInformation.TextLabel = "Gravity Strength: " + newDisc.GravityStrength.ToString() + "  Position: " + newDisc.Position.Y.ToString();
            newArrow.CameraPosition = CameraProperties.cameraPosition;
            newArrow.CameraRotation = cameraRotation;
            newDiscHud.CameraPosition = CameraProperties.cameraPosition;
            newDiscHud.CameraRotation = cameraRotation;
            newDiscHud.WiiMoteRotation = MyKeyboard.GetWiiMoteRotation();
            engine.Update();
            base.Update(gameTime);

        }








        protected override void Draw(GameTime gameTime)
        {

            //CreateArrow(gameTime);



            switch (GameState)
            {
                case GameStateDisplayingScores:
                    {
                        device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);
                        DrawScoreCard();
                        break;

                    }
                case GameStateLoadHole:
                    break;
                case GameStatePreAiming:
                    {
                        //if (Delay > 1)
                        //{
                        float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 300.0f;
                        //DrawSkyDome(viewMatrix);
                        base.Draw(gameTime);
                        //MySky.Draw(viewMatrix, CameraProperties.projectionMatrix);
                        //}
                        Power.Update();
                        AngleOfAttack.Update();
                        DiscStatus.Update();
                        PlayerStatus.Update();
                        BasketInformation.Update();
                        break;
                    }
                case GameStateAiming:
                    {

                        float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 300.0f;
                        //DrawBillboards(viewMatrix);
                        
                        base.Draw(gameTime);
                        //MySky.Draw(viewMatrix, CameraProperties.projectionMatrix);
                        Power.Update();
                        AngleOfAttack.Update();
                        DiscStatus.Update();
                        PlayerStatus.Update();
                        BasketInformation.Update();
                        

                        //Tree.DrawTrunk(Matrix.CreateScale(.001f) * Matrix.CreateTranslation(newBasket.Position), viewMatrix, CameraProperties.projectionMatrix);
                        //Tree.DrawLeaves(Matrix.CreateScale(.001f) * Matrix.CreateTranslation(newBasket.Position), viewMatrix, CameraProperties.projectionMatrix);

                        break;
                    }
                case GameStateWater:
                    DiscStatus.Update();
                    break;
                case GameStateMenu:
                    device.Clear(Color.CornflowerBlue);
                    mainMenu.Draw();
                    break;

                case GameStateVertPower:
                    {
                        float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 300.0f;
                        base.Draw(gameTime);
                        //MySky.Draw(viewMatrix, CameraProperties.projectionMatrix);
                        Power.Update();
                        AngleOfAttack.Update();
                        DiscStatus.Update();
                        PlayerStatus.Update();
                        BasketInformation.Update();
                        //Tree.DrawTrunk(Matrix.CreateScale(.001f) * Matrix.CreateTranslation(newBasket.Position), viewMatrix, CameraProperties.projectionMatrix);
                        //Tree.DrawLeaves(Matrix.CreateScale(.001f) * Matrix.CreateTranslation(newBasket.Position), viewMatrix, CameraProperties.projectionMatrix);
                        DrawVerticalBars();
                        break;
                    }
                case GameStateHorPower:
                    {
                        float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 300.0f;
                        base.Draw(gameTime);
                        //MySky.Draw(viewMatrix, CameraProperties.projectionMatrix);
                        Power.Update();
                        AngleOfAttack.Update();
                        DiscStatus.Update();
                        PlayerStatus.Update();
                        BasketInformation.Update();
                        //Tree.DrawTrunk(Matrix.CreateScale(.001f) * Matrix.CreateTranslation(newBasket.Position), viewMatrix, CameraProperties.projectionMatrix);
                        //Tree.DrawLeaves(Matrix.CreateScale(.001f) * Matrix.CreateTranslation(newBasket.Position), viewMatrix, CameraProperties.projectionMatrix);
                        DrawHorizontalPowerBars();
                        break;
                    }

                default:
                    {
                        float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 300.0f;


                        base.Draw(gameTime);
                        //MySky.Draw(viewMatrix, CameraProperties.projectionMatrix);
                        PlayerStatus.Update();
                        
                        break;
                    }

            }
            //BasketInformation.Update();
            if (DiscSelection.Visible)
            {
                DiscSelection.Draw();
            }

            //DrawArrow();



        }


        void DrawScoreCard()
        {


            SpriteBatch MySprites = new SpriteBatch(graphics.GraphicsDevice);
            MySprites.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            MySprites.Draw(ScoreBoard, new Vector2(0, 0), Color.White);
            for (int X = 0; X < NumberOfPlayers; X++)
            {
                if (Players[X].IsActive)
                {
                    MySprites.DrawString(Power.font, Players[X].Name, new Vector2(15f, 273f + (25f * X)), Color.Blue);
                    Boolean Flipper = true;
                    float Adjuster = 90f;
                    int Total = 0;
                    for (int Y = 0; Y < 18; Y++)
                    {
                        Total += Players[X].HoleScore[Y];
                        if (Flipper)
                        {
                            Adjuster += 35;
                            Flipper = false;
                        }
                        else
                        {
                            Adjuster += 36;
                            Flipper = true;
                        }
                        if (Players[X].HoleScore[Y] > 0)
                            MySprites.DrawString(Power.font, Convert.ToString(Players[X].HoleScore[Y]), new Vector2(Adjuster, 273f + (25f * X)), Color.Blue);
                        else
                            MySprites.DrawString(Power.font, "-", new Vector2(Adjuster, 273f + (25f * X)), Color.Blue);


                        //else
                        //  MySprites.DrawString(Power.font, "-", new Vector2(30f, 320f + (25f * X)), Color.Blue);

                    }
                    Adjuster += 30;
                    MySprites.DrawString(Power.font, Convert.ToString(Total), new Vector2(Adjuster, 273f + (25f * X)), Color.Blue);

                }
            }
            MySprites.End();



        }
        
        void CreateArrow(GameTime gameTime)
        {
            renderTarget = new RenderTarget2D(graphics.GraphicsDevice,
             graphics.PreferredBackBufferWidth,
             graphics.PreferredBackBufferHeight,
             1,
             SurfaceFormat.Color);
            RenderTarget oldTarget = graphics.GraphicsDevice.GetRenderTarget(0);

            graphics.GraphicsDevice.SetRenderTarget(0, renderTarget);
            graphics.GraphicsDevice.Clear(
               ClearOptions.Target,
               Color.CornflowerBlue,
               0, 0);

            //effect.Parameters["baseTexture"].SetValue(renderTarget.GetTexture());
            graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
            //newArrow.DrawNow(gameTime);
            newBasket.Visible = false;
            base.Draw(gameTime);
            newBasket.Visible = true;
            //effect.Begin();
            //effect.Techniques[0].Passes[0].Begin();
            //effect.Techniques[0].Passes[0].End();
            //effect.End();
            device.SetRenderTarget(0, null);
            Arrow = renderTarget.GetTexture();
            graphics.GraphicsDevice.SetRenderTarget(0, oldTarget as RenderTarget2D);



        }
        void DrawArrow()
        {

            SpriteBatch spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            spriteBatch.Draw(Arrow, new Vector2(0, 0), null, Color.CornflowerBlue, 0, new Vector2(0, 0), 10f, SpriteEffects.None, 1);
            //spriteBatch.Draw(Arrow, new Vector2(0, 0), null, Color.CornflowerBlue, 0, new Vector2(0, 0), SpriteEffects.None, 1);
            spriteBatch.End();
        }
        void DrawVerticalBars()
        {
            //Vertical Power

            SpriteBatch spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            spriteBatch.Draw(VerticlePower, new Vector2(graphics.PreferredBackBufferWidth / 2 - 8, graphics.PreferredBackBufferHeight / 2 - 128), null, Color.CornflowerBlue, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
            for (int x = 0; x < PowerCounter; x++)
            {
                spriteBatch.Draw(VerticleIncrement, new Vector2((graphics.PreferredBackBufferWidth / 2) - 8, graphics.PreferredBackBufferHeight / 2 + 127 - PowerCounter), null, Color.CornflowerBlue, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
            }
            if (!PowerSwitch)
            {
                PowerCounter += 6;
            }
            else
            {
                PowerCounter -= 6;
            }
            if (PowerCounter > 255)
                PowerSwitch = true;
            if (PowerCounter < 1)
                PowerSwitch = false;
            spriteBatch.End();

        }
        void DrawHorizontalPowerBars()
        {
            SpriteBatch spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            spriteBatch.Draw(HorizontalPower, new Vector2(graphics.PreferredBackBufferWidth / 2 - 128, graphics.PreferredBackBufferHeight / 2 - 8), null, Color.CornflowerBlue, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
            spriteBatch.Draw(HorizontalIncrement, new Vector2((graphics.PreferredBackBufferWidth / 2 - 127 + PowerCounter), graphics.PreferredBackBufferHeight / 2 - 8), null, Color.CornflowerBlue, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);

            if (!PowerSwitch)
            {
                PowerCounter += 6;
            }
            else
            {
                PowerCounter -= 6;
            }
            if (PowerCounter > 255)
                PowerSwitch = true;
            if (PowerCounter < 1)
                PowerSwitch = false;
            spriteBatch.End();
        }

        public static void WiiMoteCalibrated()
        {
            //MyWiimote.Calibrating = false;
            mainMenu.SwitchMenu(2);

        }
        void SetDiscInfo(int Index)
        {
            newDisc.SetTexture(DiscOptions.DiscInfo[DiscSelection.DiscIndex].Name);

        }

        public void ResetObjects()
        {
            
        }

    }
}


